package com.tang.netty.bio.client;

import com.tang.netty.bio.ChannelAdapter;
import com.tang.netty.bio.ChannelHandler;
import lombok.extern.slf4j.Slf4j;

import java.net.Socket;
import java.nio.charset.Charset;
import java.time.LocalDateTime;

@Slf4j
public class BioClientHandler extends ChannelAdapter {

    public BioClientHandler(Socket socket, Charset charset) {
        super(socket, charset);
    }

    @Override
    public void channelActive(ChannelHandler channelHandler) {
        log.info("链接IP：{}", channelHandler.socket().getLocalAddress());
        channelHandler.writeAndFlush("Now you can send bio message to us!");
    }

    @Override
    public void channelRead(ChannelHandler channelHandler, Object msg) {
        log.info("接收到消息：{}， 接收时间： {}", msg, LocalDateTime.now());
        channelHandler.writeAndFlush("Hi, we have received your message!");
    }

}
